package com.raymond.smgp.msg.tlv;



public class TLVString extends TLV {
	private String value;


	public TLVString(short tag) {
		super(tag);
	}

	public TLVString(short tag, String value) {
		super(tag);
		this.value = value;
	}

	@Override
	public byte[] getValueData()  {
		if(value == null) {
			return null;
		}
		byte[] valueBytes = value.getBytes();
		byte[] buffer = new byte[valueBytes.length + 1];
		System.arraycopy(valueBytes, 0, buffer, 0, valueBytes.length);
		buffer[valueBytes.length] = 0;
		return buffer;
	}

	@Override
	public void setValueData(byte[] valueData) {
		this.value = new String(valueData);
	}

	@Override
	public short getLength() {
		if (value == null) {
			return 0;
		}
		return (short) value.getBytes().length;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;

	}

}